<template>
 <div>
<el-card>
  <div id="main" style="width:600px;height:400px"></div>
</el-card>
 </div>
</template>

<script>
import * as echarts from 'echarts'
import _ from 'lodash'
import request from '@/Utils/request'
export default {
  name: 'ReportsView',
  data () {
    return {
      // 需要合并的数据
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      },
      newoptions: []
    }
  },
  components: {

  },
  created () {

  },
  async mounted () {
    await this.getChartOption()
    const mychart = echarts.init(document.getElementById('main'))
    const result = _.merge(this.newoptions, this.options)

    mychart.setOption(result)
  },
  methods: {
    async getChartOption () {
      const { data } = await request({
        url: 'reports/type/1'
      })
      if (data.meta.status !== 200) {
        this.$message({
          type: 'error',
          message: '表单数据获取失败'
        })
      }
      console.log(data)
      this.newoptions = data.data
    }
  },
  computed: {},
  watch: {}
}
</script>

<style scoped>

</style>
